package com.runoob;

public class MementoPatternDemo {
    public static void main(String[] args) {
        Originator originator = new Originator();
        CareTaker careTaker = new CareTaker();
        originator.setState("状态 #1");
        originator.setState("状态 #2");
        System.out.println("第一次保存的状态：" + originator.getState());
        careTaker.add(originator.saveStateToMemento());
        originator.setState("状态 #3");
        System.out.println("第二次保存的状态：" + originator.getState());
        careTaker.add(originator.saveStateToMemento());
        originator.setState("状态 #4");

        System.out.println("当前状态: " + originator.getState());
        originator.getStateFromMemento(careTaker.get(0));
        System.out.println("恢复到第一次保存的状态: " + originator.getState());
        originator.getStateFromMemento(careTaker.get(1));
        System.out.println("恢复到第二次保存的状态: " + originator.getState());
    }
}
